// axios({
//     url:'/student/list',
//     method:'get'
// })
// .then(res=>{
//     console.log(res);
// })

//写登录和注册界面的切换
let registerbox = document.querySelector('.register');
let loginbox = document.querySelector('.login');
let login_a = document.querySelector('.login-a');
let register_a = document.querySelector('.register-a');


//页面先显示登录框先写登录连接
//点击去注册：显示注册框隐藏登录框
login_a.addEventListener('click', () => {
    loginbox.style.display = 'none'
    registerbox.style.display = 'block'
})
//点击去登录：显示登录框隐藏注册框
register_a.addEventListener('click', () => {
    loginbox.style.display = 'block'
    registerbox.style.display = 'none'
})

//点击注册请求
registerbox.querySelector('form').addEventListener("submit", function (e) {
    e.preventDefault()
    let data = $(this).serialize()
    axios.post('/api/register', data)
        .then(res => {
            if (res.data.code === 0) {
                toastr.success(res.data.message)
                register_a.click()
            }
        })
})

//点击登录
loginbox.querySelector('form').addEventListener("submit", function (e) {
    e.preventDefault()
    let data = $(this).serialize()
    axios.post('/api/login', data)
        .then(res => {
            if (res.data.code === 0) {
                localStorage.setItem('tokens',res.data.token)
                toastr.success(res.data.message)
                location.href = './index.html'
            }
        })
})